package net.zjitc.controller;

import net.zjitc.common.Msg;
import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author admin
 * @Date 2019/3/27 13:34
 */
@Controller
public class registerController {
    @Autowired
    UserService userService;
    @RequestMapping(value = "/register")
    public String register(User user, Model model){
//        String username = user.getUsername();
//        String password = user.getPassword();
//        String email = user.getEmail();
//        User e = userService.checkemail(email);
//        User u = userService.checkname(username);
//            user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
        return "";
    }

    @RequestMapping(value = "/checkName")
    @ResponseBody
    public Msg checkName(User user){
        User u = userService.checkname(user.getUsername());
        Msg msg = new Msg();
        if (u != null)
        {
            msg.setFlag(false);
        }else {
            msg.setFlag(true);
        }
        return msg;
    }

    @RequestMapping(value = "/checkEmail")
    @ResponseBody
    public Msg checkEmail(User user){
        User u = userService.checkemail(user.getEmail());
        Msg msg = new Msg();
        if (u != null)
        {
            msg.setFlag(false);
        }else {
            msg.setFlag(true);
        }
        return msg;
    }
}
